// pages/index/classifyList/classifyList.js
import {list} from '../../../../api/navigation'
const util = require('../../../../utils/util.js')
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    info:{
      type:Object
    }
},
  lifetimes:{
    attached(){
      if (this.data.info.tagids != null) {
        this.data.tagIds = this.data.info.tagids.split(',')
        for (var i = 0; i < this.data.tagIds.length; i++) {
          this.data.tagIds[i] = parseInt(this.data.tagIds[i])
        }
      }
        this.setData({
          tagIds:this.data.tagIds
        })
      
      this.loadNavigation()
    }
      
  },
  /**
   * 组件的初始数据
   */
  data: {
    tagIds:[],
    navigations:[],
    pageSize:6
  },

  /**
   * 组件的方法列表
   */
  methods: {
    loadNavigation(){
      list({
        mchId:app.globalData.mchId,
        pageSize:this.data.pageSize,
        tagIds:this.data.tagIds
      }).then(res=>{
            this.data.navigations=res.data.data
            this.data.navigations.forEach(function (item) {
              item.logo = util.thumbnail(item.logo,96,96)
            })
            this.setData({
              navigations: this.data.navigations
            })
      })
    },
    toRecommend(e){
      console.log(e)
      if(e.currentTarget.dataset.id.type==1){
        wx.navigateTo({
          url: '/pages/goods/category/category?id='+e.currentTarget.dataset.id.typeId
       })
      }
            if (e.currentTarget.dataset.id.type == 2) {
                    wx.navigateTo({
                            url: '/pages/index/wxPage/wxPage?id=' + e.currentTarget.dataset.id.typeId
                    })
            }
      if(e.currentTarget.dataset.id.type==3){
        wx.navigateTo({
          url: '/pages/goods/product/details?id='+e.currentTarget.dataset.id.typeId,
        })
      }
      if(e.currentTarget.dataset.id.type==12){
        window.location.href = e.currentTarget.dataset.id.url
      }
    },
  }
})
